package com.web.expspringboot;

import com.web.expspringboot.entity.UserSt;
import com.web.expspringboot.mapper.ProductMapper;
import com.web.expspringboot.mapper.UserMapper;
import com.web.expspringboot.service.PurchaseService;
import com.web.expspringboot.service.ProductService;
import com.web.expspringboot.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class SpringbootTestUserService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    ProductMapper productMapper;

    @Autowired
    ProductService productService;

    @Autowired
    UserService userService;

    @Autowired
    PurchaseService messageService;

    /**
     * 生成测试用户，id从1000到1009
     */
    @Test
    void generateTestUsers(){
        UserSt user = new UserSt();
        for (int i = 0; i < 10; i++) {
            user.setUserPassword("123456");
            user.setUserId(i + 1000);
            user.setUserAccount("12312341234");
            user.setUserName("TestUser" + i);
            user.setUserBanned(0);
            user.setIsManager(0);
            userMapper.insertUser(user);
        }
    }

    @Test
    void alterPhoneNum(){
        List<UserSt> allUsers = userMapper.getAllUser();
        for (UserSt user : allUsers) {
            if (user.getUserId() >= 1000){
                user.setUserAccount("1231234" + user.getUserId());
                userMapper.updateUser(user);
            }

        }
    }

}
